package github.saw96x.registry.zk;

import github.saw96x.registry.ServiceRegistry;
import github.saw96x.registry.zk.util.CuratorUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;

import java.net.InetSocketAddress;

/**
 * @author Saw96x
 * @date 2022/3/18 10:43
 */
@Slf4j
public class ZkServiceRegistryImpl implements ServiceRegistry {

  @Override
  public void registerService(String rpcServiceName, InetSocketAddress inetSocketAddress) {
    String servicePath = CuratorUtils.ZK_REGISTER_ROOT_PATH + "/" + rpcServiceName + inetSocketAddress.toString();
    CuratorFramework zkClient = CuratorUtils.getZkClient();
    CuratorUtils.createPersistentNode(zkClient, servicePath);
  }
}
